﻿<template>
  <div class="car_case-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" :inline="true">

        <el-form-item label="案例标题">
          <el-input v-model="queryParams.title" clearable="" placeholder="请输入案例标题" />
        </el-form-item>


        <el-form-item label="质感">
          <el-select clearable="" filterable v-model="queryParams.zhiganId" placeholder="请选择质感">
            <el-option v-for="(item, index) in car_zhiganDropdownList" :key="index" :value="item.value"
              :label="item.label" />
          </el-select>
        </el-form-item>

        <el-form-item label="颜色">
          <el-select clearable="" filterable v-model="queryParams.colorId" placeholder="请选择颜色">
            <el-option v-for="(item, index) in car_color2DropdownList" :key="index" :value="item.value"
              :label="item.label" />
          </el-select>
        </el-form-item>

        <el-form-item label="车型">

          <el-cascader filterable v-model="queryParams.carTree" :options="car_carDropdownList"   />

          <!-- <el-select clearable="" filterable="" v-model="queryParams.carid" placeholder="请选择车型">
            <el-option v-for="(item,index) in car_carDropdownList" :key="index" :value="item.value" :label="item.label" />
          </el-select> -->
        </el-form-item>



        <el-form-item label="系列">
          <el-cascader filterable v-model="queryParams.xilieTree" :options="car_colorDropdown"   />

        </el-form-item>



        <el-form-item label="色系">
          <el-select clearable="" filterable v-model="queryParams.sexiId" placeholder="请选择色系">
            <el-option v-for="(item, index) in car_SeXiDropdownList" :key="index" :value="item.value"
              :label="item.label" />

          </el-select>

        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'car_case:page'"> 查询 </el-button>
            <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>

          </el-button-group>

        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="ele-Plus" @click="openAddcar_case" v-auth="'car_case:add'"> 新增 </el-button>

        </el-form-item>

        <!-- <el-form-item>
          <el-button type="primary" icon="ele-Plus" @click="openAddcar_casePL" v-auth="'car_case:add'"> 批量导入
          </el-button>

        </el-form-item> -->


      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 8px">
      <el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" border="">
        <el-table-column type="index" label="id" width="120" align="center" fixed="">
          <template #default="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="title" label="案例标题" fixed="" show-overflow-tooltip="" />

        <el-table-column prop="coverurl" label="封面图" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <el-image style="width: 60px; height: 60px" :src="scope.row.coverurl" :lazy="true"
              :hide-on-click-modal="true" :preview-src-list="[scope.row.coverurl]" :initial-index="0" fit="scale-down"
              preview-teleported="" />
          </template>
        </el-table-column>


        <el-table-column prop="tag_car" label="车型" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <span v-for="(item,index) in  scope.row.tag_car">{{ item.title}} <br v-if="index%2==1"> </span>
          </template>
        </el-table-column>

        <el-table-column prop="tag_color" label="颜色" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <span v-for="(item,index) in  scope.row.tag_color">{{ item.title}}   <br> </span>
          </template>
        </el-table-column>

        <el-table-column prop="tag_sexi" label="色系" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <span v-for="(item,index) in  scope.row.tag_sexi">{{ item.title}}  <br></span>
          </template>
        </el-table-column>

        <el-table-column prop="tag_xilie" label="系列" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <span v-for="(item,index) in  scope.row.tag_xilie">{{ item.title}} <br v-if="index%2==1"></span>
          </template>
        </el-table-column>

        <el-table-column prop="tag_zhigan" label="质感" fixed="" show-overflow-tooltip="">
          <template #default="scope">
            <span v-for="(item,index) in  scope.row.tag_zhigan">{{ item.title}}  <br></span>
          </template>
        </el-table-column>


   
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip=""
          v-if="auth('car_case:edit') || auth('car_case:delete')">
          <template #default="scope">
          <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditcar_case(scope.row)"
              v-auth="'car_case:edit'"> 编辑 </el-button> 
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delcar_case(scope.row)"
              v-auth="'car_case:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-model:currentPage="tableParams.page" v-model:page-size="tableParams.pageSize"
        :total="tableParams.total" :page-sizes="[10, 20, 50, 100]" small="" background=""
        @size-change="handleSizeChange" @current-change="handleCurrentChange"
        layout="total, sizes, prev, pager, next, jumper" />
      <editDialog ref="editDialogRef" :title="editcar_caseTitle" @reloadTable="handleQuery" />
      <!-- <plInput  ref="editDialogPLRef" title="批量导入" @reloadTable="handleQuery" /> -->
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="car_case">
import { ref } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { auth } from '/@/utils/authFunction';
//import { formatDate } from '/@/utils/formatTime';


import plInput from '/@/views/main/car_case/component/plInput.vue'
import editDialog from '/@/views/main/car_case/component/editDialog.vue'
import { pagecar_case, deletecar_case } from '/@/api/main/car_case';
import { getcar_carDropdown } from '/@/api/main/car_case';
import { getcar_color2Dropdown } from '/@/api/main/car_case';
import { getcar_zhiganDropdown } from '/@/api/main/car_case';
import { getcar_SeXiDropdown } from '/@/api/main/car_case';
import { getcar_colorDropdown } from '/@/api/main/car_case';


const editDialogRef = ref();
const editDialogPLRef = ref();
const loading = ref(false);
const tableData = ref<any>
  ([]);
const queryParams = ref<any>
  ({});
const tableParams = ref({
  page: 1,
  pageSize: 10,
  total: 0,
});
const editcar_caseTitle = ref("");


// 查询操作
const handleQuery = async () => {
  loading.value = true;

  if (queryParams.value.carTree && queryParams.value.carTree.length > 1) {
    queryParams.value.carid = queryParams.value.carTree[1]
  }
  if (queryParams.value.xilieTree && queryParams.value.xilieTree.length > 1) {
    queryParams.value.xilieId = queryParams.value.xilieTree[0]
    queryParams.value.xilieSubId = queryParams.value.xilieTree[1]
  }


 if(queryParams.value.carid=="")
{
  delete queryParams.value.carid;
}
 if(queryParams.value.colorId=="")
{
  delete queryParams.value.colorId;
}
 if(queryParams.value.zhiganId=="")
{
  delete queryParams.value.zhiganId;
}
 if(queryParams.value.xilieSubId=="")
{
  delete queryParams.value.xilieSubId;
}
 if(queryParams.value.sexiId=="")
{
  delete queryParams.value.sexiId;
}



  var res = await pagecar_case(Object.assign(queryParams.value, tableParams.value));
  tableData.value = res.data.result?.items ?? [];
  tableParams.value.total = res.data.result?.total;
  loading.value = false;
};
// 打开批量导入
const openAddcar_casePL = () => {
  
  editDialogPLRef.value.openDialog({});
};

// 打开新增页面
const openAddcar_case = () => {
  editcar_caseTitle.value = '添加案例';
  editDialogRef.value.openDialog({});
};

// 打开编辑页面
const openEditcar_case = (row: any) => {
  editcar_caseTitle.value = '编辑案例';
  editDialogRef.value.openDialog(row);
};

// 删除
const delcar_case = (row: any) => {
  ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      await deletecar_case(row);
      handleQuery();
      ElMessage.success("删除成功");
    })
    .catch(() => { });
};

// 改变页面容量
const handleSizeChange = (val: number) => {
  tableParams.value.pageSize = val;
  handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
  tableParams.value.page = val;
  handleQuery();
};


const car_colorDropdown = ref<any>([]);
const getcar_colorDropdownList = async () => {
  let list = await getcar_colorDropdown();
  car_colorDropdown.value = list.data.result ?? [];
};
getcar_colorDropdownList();



const car_carDropdownList = ref<any>([]);
const getcar_carDropdownList = async () => {
  let list = await getcar_carDropdown();
  car_carDropdownList.value = list.data.result ?? [];
};
getcar_carDropdownList();

const car_color2DropdownList = ref<any>([]);
const getcar_color2DropdownList = async () => {
  let list = await getcar_color2Dropdown();
  car_color2DropdownList.value = list.data.result ?? [];
};
getcar_color2DropdownList();

const car_zhiganDropdownList = ref<any>([]);
const getcar_zhiganDropdownList = async () => {
  let list = await getcar_zhiganDropdown();
  car_zhiganDropdownList.value = list.data.result ?? [];
};
getcar_zhiganDropdownList();

//         const treeOutputTreeOutputDropdownList = ref<any>([]); 
// const getTreeOutputTreeOutputDropdownList = async () => {
//     let list = await getTreeOutputTreeOutputDropdown();
//     treeOutputTreeOutputDropdownList.value = list.data.result ?? [];
// };
// getTreeOutputTreeOutputDropdownList();

const car_SeXiDropdownList = ref<any>([]);
const getcar_SeXiDropdownList = async () => {
  let list = await getcar_SeXiDropdown();
  car_SeXiDropdownList.value = list.data.result ?? [];
};
getcar_SeXiDropdownList();


handleQuery();
//将属性或者函数暴露给父组件

</script>
